#ifndef ITEMCREATOR_H
#define ITEMCREATOR_H

#include <BMPackSim_global.h>
#include <corelib\kernel\qobject.h>
#include <gui\graphicsview\qgraphicsitem.h>
#include <corelib\kernel\qtimer.h>



namespace PackSim
{

	class EllipseItem;

	class PICKBUSINESS_EXPORT ItemCreator : public QObject,  public QGraphicsRectItem 
	{
		Q_OBJECT

	public:
		ItemCreator(QGraphicsItem* parent = 0);
		~ItemCreator();

		void startCreation();
		void stopCreation();
		void update(int aDeltaTime );

		QColor color() const;
		void setColor(QColor color);

		int columNumber() const ;
		void setColumNumber(int columNumber);
		int columnPitch() const ;
		void setColumnPitch(int columnPitch);
		int rowNumber() const ;
		void setRowNumber(int rowNumber) ;
		int rowPitch() const ;
		void setRowPitch(int rowPitch) ;
		
		inline int creationPeriod() const { return mCreationPeriod; }
		inline void setCreationPeriod(int val) { mCreationPeriod = val; }
		
		inline QRectF itemRect() const { return mItemRect; }
		inline void setItemRect(QRectF itemRect) { mItemRect = itemRect; }
		
		inline double itemRotation() const { return mItemRotation; }
		inline void setItemRotation(double itemRotation) { mItemRotation = itemRotation; }
		
		inline QColor itemColor() const { return mItemColor; }
		inline void setItemColor(QColor itemColor) { mItemColor = itemColor; }

	signals:

		void ItemCreatorSignalItemsCreated(ItemCreator* itemCreator, QList<EllipseItem*>& itemList);
	
	private slots:

		void onCreationTimerTimeOut();

	private:
		
		void setRect( const QRectF & rectangle );
		void setRect( qreal x, qreal y, qreal width, qreal height );

		void resizeCreator();

		void createItems();

		int mColumNumber;
		int mColumnPitch;
		int mRowNumber;
		int mRowPitch;
		
		int mCreationPeriod;
		int mTimeSinceCreated;
		
		QTimer mCreationTimer;

		QRectF mItemRect;
		double mItemRotation;
		QColor mItemColor;
		QColor mColor;
		QList<EllipseItem*> mItemList;



	};

}
#endif // ITEMCREATOR_H
